package liuwanghui.util;

import liuwanghui.constant.CommonConstant;
import lombok.experimental.UtilityClass;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@UtilityClass
public class DateUtil {
    
    public static final String DEFAULT_FORMAT = CommonConstant.DEFAULT_DATE_FORMAT;
    
    public String format(LocalDateTime dateTime) {
        return dateTime.format(DateTimeFormatter.ofPattern(DEFAULT_FORMAT));
    }
    
    public LocalDateTime parse(String dateStr) {
        return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(DEFAULT_FORMAT));
    }
    
    public LocalDateTime getStartOfDay() {
        return LocalDateTime.now().with(LocalTime.MIN);
    }
    
    public LocalDateTime getEndOfDay() {
        return LocalDateTime.now().with(LocalTime.MAX);
    }
    
    public LocalDateTime getStartOfMonth() {
        return LocalDateTime.now()
            .withDayOfMonth(1)
            .with(LocalTime.MIN);
    }
    
    public LocalDateTime getEndOfMonth() {
        return LocalDateTime.now()
            .withDayOfMonth(LocalDateTime.now().getMonth().length(LocalDateTime.now().toLocalDate().isLeapYear()))
            .with(LocalTime.MAX);
    }
} 